package businesslogic.Updatebl;

import PO.RoomPO;
import PO.UpdateRoomPO;
import VO.RoomVO;
import VO.UpdateRoomVO;
import dao.UpdateDao.UpdateDao;
import dao.UpdateDao._stub.UpdateDao_stub;
import util.Message;

/**
 * Created by insomnia on 2016/11/17.
 * 房间信息方法的具体实现
 * @author insomnia
 */
public class Room {
    /**持有dao层的应用，*/
    UpdateDao update;
    /**构造函数*/
    public Room(){
        update=new UpdateDao_stub();//这里将update初始化为stub；
    }
    /***
     * 根据酒店用户名得到该酒店的房间信息
     * @param hotelManagerID
     * @return得到的房间信息
     */
    public RoomVO getRoomInfo(String hotelManagerID) {
        RoomPO room =update.getRoomInfo(hotelManagerID);
        return roomPoToVo(room);
    }
    /***
     * 更新酒店房间信息，检查信息是否合法
     * @param updateRoomVO
     * @return 是否更改成功或对应的非法错误
     */
    public Message updateRoomInfo(UpdateRoomVO updateRoomVO) {
        if(updateRoomVO.getChange()==-1          //检查是否有未完成的
                ||updateRoomVO.getRoomType()==null
                ||updateRoomVO.getHotelManagerID()==null){
            return Message.NOT_COMPLETE;
        }else {
            UpdateRoomPO updateRoomPO=updateRoomVoToPo(updateRoomVO);
            boolean flag=update.updateRoomInfo(updateRoomPO);
            if(flag){
                return Message.SUCCESS;
            }else{
                return  Message.FAIL;
            }
        }
    }

    /***
     * 将roomPO转化为RoomVO
     * @param roomPO
     * @return roomVO
     */
    private RoomVO roomPoToVo(RoomPO roomPO){
        RoomVO roomVO=new RoomVO(roomPO.getStrandRoom(),
                roomPO.getDoubleRoom(),
                roomPO.getFamilyRoom()
        );
        return roomVO;
    }
    /***
     * 将updateRoomVO转化为updateRoomPO
     * @param updateRoomVO
     * @return updateRoomPO
     */
    private UpdateRoomPO updateRoomVoToPo(UpdateRoomVO updateRoomVO){
        UpdateRoomPO updateRoomPO=new UpdateRoomPO(updateRoomVO.hotelManagerID,
                updateRoomVO.getRoomType(),
                updateRoomVO.getChange()
        );
        return updateRoomPO;
    }


}
